import { Ref, ref, watch } from "vue";
import { controlDevice } from "../shared";

/*
 * @Author: ReinerLau lk850593913@gmail.com
 * @Date: 2023-02-03 15:56:16
 * @LastEditors: ReinerLau lk850593913@gmail.com
 * @LastEditTime: 2023-02-03 15:59:48
 * @FilePath: \v2.0.0\src\views\patroling\composables\useLaserControl.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
interface Options {
  caritem: Ref<string>;
}
export default (options: Options) => {
  const { caritem } = options;
  const disperseMode = ref(false);
  watch(disperseMode, controlLaser);
  function toggleLaser() {
    disperseMode.value = !disperseMode.value;
  }

  function controlLaser() {
    const data = {
      code: caritem.value,
      param1: "09",
      param2: disperseMode.value ? "1" : "0",
      param3: "0",
      param4: "0",
    };
    controlDevice(data);
  }

  return {
    disperseMode,
    toggleLaser,
  };
};
